package com.Util.serviceUtil;

import com.Util.Config;
import com.google.gson.JsonArray;
import com.google.gson.JsonObject;
import com.google.gson.JsonParser;

/**
 * 翻译
 */
public class TransUntil {

    private static final String APP_ID = Config.APP_ID;
    private static final String SECURITY_KEY = Config.SECURITY_KEY;
    private static  TransApi  api=null;

    static {
         api = new TransApi(APP_ID, SECURITY_KEY);
    }
    public static void main(String[] args) throws Exception {
        String query = "高度600米";
        System.out.println(api.getTransResult(query, "auto", "en"));
    }

    /**
     * 根据结果返回JsonObject
     * @param query
     * @param from
     * @param to
     * @return
     * @throws Exception
     */
    public static JsonArray getResult(String query, String from, String to) throws Exception{
        String result=api.getTransResult ( query,from,to );
        JsonObject jsonObject=new JsonParser ().parse ( result ).getAsJsonObject ();
        JsonArray trans_result=jsonObject.getAsJsonArray ( "trans_result" );
        return trans_result;
    }
}
